package cn.jorian.framework.util;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class ImageUtil {

    public static void strToImage(String base64Str) throws IOException {
//        File file = new File("F:\\IdeaProjects\\HelloJava\\b.txt");
//        FileInputStream inputStream = new FileInputStream(file);

//        byte[] source = base64Str.getBytes(StandardCharsets.UTF_8);
//
//        ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
//        arrayOutputStream.write(source);
//        String str = new String(arrayOutputStream.toByteArray());
//        System.out.println(str);
//        arrayOutputStream.flush();
//        arrayOutputStream.close();

        Base64.Decoder decoder = Base64.getDecoder();
        byte[] result = decoder.decode(base64Str);
        File image = new File("F:\\IdeaProjects\\HelloJava\\2.jpg");
        image.createNewFile();
        FileOutputStream fileOutputStream = new FileOutputStream(image);
        fileOutputStream.write(result);
        fileOutputStream.flush();
        fileOutputStream.close();
    }
}
